var socketSetup = function() {
	if(typeof(WebSocket) !== 'undefined') {
		socket = new WebSocket('ws://localhost:8080');
		socket.onopen = function() {
			multiPlayer = true;
			document.title = 'SpaceShoot MULTIPLAYER';
		};		
		socket.onclose = function() {
			
		};		
		socket.onmessage = function(e) {
			var obj = JSON.parse(e.data);
			
			if(obj.asteroid) {
				var a = obj.asteroid;
				asteroids.push(new asteroid(a.size, a.life, a.angle, a.rotation, a.x, a.y, a.vx, a.vy));
			} else if(obj.added) {
				for(var i = obj.added.length; i--; )
					ships.push(new ship(obj.added[i], { }, ships.length));
			} else if(obj.removed) {
				for(var i = ships.length; i--; )
					if(ships[i].id === obj.removed) {
						ships.slice(i, 1);
						break;
					}
			} else if(obj.logic) {
				for(var i = ships.length; i--; )
					if(ships[i].id === obj.logic.ship.id) {
						ships[i].control.shoot = obj.logic.keyboard.shoot;
						ships[i].control.left = obj.logic.keyboard.left;
						ships[i].control.right = obj.logic.keyboard.right;
						ships[i].control.up = obj.logic.keyboard.up;
						ships[i].control.down = obj.logic.keyboard.down;
						ships[i].boost = obj.logic.ship.boost;
						ships[i].angle = obj.logic.ship.angle;
						ships[i].x = obj.logic.ship.x;
						ships[i].y = obj.logic.ship.y;
						ships[i].life = obj.logic.ship.life;
						ships[i].ammo = obj.logic.ship.ammo;
						ships[i].hitByAsteroid = obj.logic.ship.hitByAsteroid;
						ships[i].hitAsteroids = obj.logic.ship.hitAsteroids;
						ships[i].shotAsteroids = obj.logic.ship.shotAsteroids;
						ships[i].hitShips = obj.logic.ship.hitShips;
						break;
					}
			}
			else if(obj.status) {
				ships[0].x = obj.status.x;
				ships[0].y = obj.status.y;
				gameRunning = true;
			}
		};
	} else
		gameRunning = true;
};